package com.lonwin.mes2u8.domain.mes;

import com.google.common.collect.Lists;
import com.lonwin.mes2u8.common.CommonValue;
import com.lonwin.mes2u8.domain.u8.U8InventoryAddParam;
import com.lonwin.mes2u8.domain.u8.U8InventoryBatchQueryParam;
import com.lonwin.mes2u8.util.BaseInfoU8;
import lombok.Data;

import java.math.BigDecimal;

/**
 * mes存货返回对象
 * @author DELL
 * @Date 2023-12-12 17:16
 */
@Data
public class MesInventoryQueryResult {
    // 批次号
    private String bno;
    // 产品标识
    private String productIdentification;
    // 法兰名称
    private String flangeName;
    // 规格型号
    private String spec;
    // 材质
    private String materialQuality;
    // 任务数量
    private String tasksNum;
    // 成品单重 -- 图纸重量
    private Double singleWeight;

    /**
     * 构建U8中的存货查询参数
     * @param from_account 调用方id
     * @param to_account 提供方id
     * @param app_key 应用编码
     * @return
     */
    public U8InventoryBatchQueryParam buildU8InventoryBatchQueryParamByMes(
            String from_account, String to_account, String app_key
    ) {
        return U8InventoryBatchQueryParam.builder()
                .from_account(from_account)
                .to_account(to_account)
                .app_key(app_key)
                .token(BaseInfoU8.getToken())
                .name(this.flangeName)
                .build();
    }

    /**
     * 构建U8中的存货新增参数
     * @return
     */
    public U8InventoryAddParam buildU8InventoryAddParamByMes() {
        return U8InventoryAddParam.builder()
                .code(productIdentification.replace("-", ""))
                .name(this.flangeName)
                .specs(this.spec)
                .sort_code(CommonValue.U8_INVENTORY_CLASS_CODE)
                .unitgroup_code(CommonValue.U8_INVENTORY_UNIT_GROUP_CODE).unitgroup_name(CommonValue.U8_INVENTORY_UNIT_GROUP_NAME)
                .unitgroup_type(CommonValue.U8_INVENTORY_UNIT_GROUP_TYPE)
                .main_measure(CommonValue.U8_INVENTORY_UNIT_CODE_1).ccomunitname(CommonValue.U8_INVENTORY_UNIT_NAME_1)
                .puunit_code(CommonValue.U8_INVENTORY_UNIT_CODE_2).puunit_name(CommonValue.U8_INVENTORY_UNIT_NAME_2)
                .saunit_code(CommonValue.U8_INVENTORY_UNIT_CODE_2).saunit_name(CommonValue.U8_INVENTORY_UNIT_NAME_2)
                .stunit_code(CommonValue.U8_INVENTORY_UNIT_CODE_2).stunit_name(CommonValue.U8_INVENTORY_UNIT_NAME_2)
                .caunit_code(CommonValue.U8_INVENTORY_UNIT_CODE_2).caunit_name(CommonValue.U8_INVENTORY_UNIT_NAME_2)
                .cAssComunitCode(CommonValue.U8_INVENTORY_UNIT_CODE_2)
                .cProductUnit(CommonValue.U8_INVENTORY_UNIT_CODE_2)
                .cshopunit(CommonValue.U8_INVENTORY_UNIT_CODE_2)
                .sale_flag(CommonValue.U8_TRUE).prod_consu_flag(CommonValue.U8_TRUE).bProxyForeign(CommonValue.U8_TRUE).selfmake_flag(CommonValue.U8_TRUE)
                .cSRPolicy("PE")
                .iimptaxrate(new BigDecimal("13.000")).tax_rate(new BigDecimal("13.000"))
                .bbommain(CommonValue.U8_TRUE).bbomsub(CommonValue.U8_TRUE).bproductbill(CommonValue.U8_TRUE)
                .self_define1("")
                .self_define2(materialQuality)
                .entry(Lists.newArrayList(U8InventoryAddParam.InventoryFree.builder().invcode(productIdentification.replace("-", "")).build()))
                .build();
    }
}
